//
//  DrawView.m
//  30203笑哭脸
//
//  Created by student on 16/4/6.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "DrawView.h"

@implementation DrawView

- (void)setType:(int)type
{
    _type = type;
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [self drawGraphics:rect];
}

- (void)drawGraphics:(CGRect)rect
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    CGPoint center = CGPointMake(rect.size.width/2, rect.size.height/2);
    [path moveToPoint:center];
    CGFloat radius = rect.size.width/2*0.8;
    CGFloat startAngle = - M_PI_2;
    CGFloat endAngle = M_PI * 2;
    [path addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
    [[UIColor blueColor] setStroke];
    [[UIColor whiteColor] setFill];
    path.lineWidth = 10;
    [path stroke];
    [path fill];
    
    
    //眼睛左
    UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(120, 300) radius:30 startAngle:0 endAngle:M_PI*2 clockwise:YES];
    path2.lineWidth = 10;
    [[UIColor blueColor] setStroke];
    [[UIColor whiteColor] setFill];
    [path2 stroke];
    [path2 fill];
    
    //眼睛右
    UIBezierPath *path3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(300, 300) radius:30 startAngle:0 endAngle:M_PI*2 clockwise:YES];
    path3.lineWidth = 10;
    [[UIColor blueColor] setStroke];
    [[UIColor whiteColor] setFill];
    [path3 stroke];
    [path3 fill];
    
    
    if(self.type == 1)
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(ctx, 100, 250);
        CGContextAddQuadCurveToPoint(ctx, 207, 150, 300, 250);
        CGContextSetLineWidth(ctx, 10);
        [[UIColor blueColor] setStroke];
        CGContextStrokePath(ctx);
        NSLog(@"%i",self.type);
    }
    else if (self.type == 2)
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(ctx, 100, 250);
        CGContextAddQuadCurveToPoint(ctx, 207, 300, 300, 250);
        CGContextSetLineWidth(ctx, 10);
        [[UIColor blueColor] setStroke];
        CGContextStrokePath(ctx);
        NSLog(@"%i",self.type);
    }
    else
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(ctx, 100, 250);
        CGContextAddQuadCurveToPoint(ctx, 207, 350, 300, 250);
        CGContextSetLineWidth(ctx, 10);
        [[UIColor blueColor] setStroke];
        CGContextStrokePath(ctx);
        NSLog(@"%i",self.type);
    }
}
@end
